# -*- coding: utf-8 -*-
import pandas as pd
from utils import get_checkpoints
import sys

path = sys.argv[1]

results = pd.read_csv(path, index_col=None)

log_dirs = results['log_dir'].tolist()


# print(log_dirs)

dev_accs = []
for dir in log_dirs:
    dev_acc = 0
    ckpts = get_checkpoints(dir)
    if None in ckpts:
        dev_accs.append("Not 10 fold enough")
        continue
    for ckpt in ckpts:
        dev_acc += float(ckpt.split(".ckpt")[0].split("/")[-1])
    dev_acc /= 10
    dev_acc_round = round(dev_acc * 100, 3)
    dev_accs.append(dev_acc_round)

results['dev_acc'] = dev_accs
results.to_csv("results_with_dev_acc.csv")
print("done\nthe results with dev_acc save as results_with_dev_acc.csv")